package com.solocredit.finance.data.dv.utils

import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.Build
import android.os.SystemClock
import android.provider.Settings
import java.util.Locale
import java.util.TimeZone

object DvAplUtil {
    @SuppressLint("HardwareIds")
    fun anroiId(context: Context): String {
        return Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID) ?: ""
    }

    fun phType(context: Context): String {
        return ""
    }

    fun lang(): String {
        return try {
            Locale.getDefault().language
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun disLang(): String {
        return try {
            Locale.getDefault().displayLanguage
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun isoLang(): String {
        return try {
            Locale.getDefault().isO3Language
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun isoCtry(): String {
        return try {
            Locale.getDefault().isO3Country
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun tzID(): String {
        return try {
            TimeZone.getDefault().id
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    @SuppressLint("ServiceCast")
    fun wiType(context: Context): String {
        return try {
            val connectivityManager =
                context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
            val network = connectivityManager.activeNetworkInfo
            if (network != null && network.isConnected) {
                when (network.type) {
                    ConnectivityManager.TYPE_WIFI -> "WIFI"
                    ConnectivityManager.TYPE_MOBILE -> "MOBILE"
                    else -> ""
                }
            } else {
                ""
            }
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun sioName(context: Context): String {
        return ""
    }

    fun isDg(context: Context): String {
        return try {
            val applicationInfo = context.applicationInfo
            if (applicationInfo != null && applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
                "YES"
            } else {
                "NO"
            }
        } catch (e: Exception) {
            e.printStackTrace()
            "NO"
        }
    }

    fun elaptime(): String {
        return try {
            SystemClock.elapsedRealtime().toString()
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun lastBTime(): String {
        return try {
            (System.currentTimeMillis() - SystemClock.elapsedRealtime()).toString()
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun verName(context: Context): String {
        return try {
            val packageInfo = context.packageManager.getPackageInfo(
                context.packageName,
                PackageManager.GET_ACTIVITIES
            )
            packageInfo.versionName ?: "1.0"
        } catch (e: Exception) {
            e.printStackTrace()
            "1.0"
        }
    }

    fun verCode(context: Context): String {
        return try {
            val packageInfo = context.packageManager.getPackageInfo(
                context.packageName,
                PackageManager.GET_ACTIVITIES
            )
            packageInfo.versionCode.toString()
        } catch (e: Exception) {
            e.printStackTrace()
            "1"
        }
    }

    fun siState(context: Context): String {
        return ""
    }

    fun cpSerial(): String {
        return try {
            Build.SUPPORTED_ABIS[0]
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun dHht(context: Context): String {
        return try {
            context.resources.displayMetrics.heightPixels.toString()
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun dwh(context: Context): String {
        return try {
            context.resources.displayMetrics.widthPixels.toString()
        } catch (e: Exception) {
            e.printStackTrace()
            ""
        }
    }

    fun area(): String {
        return Locale.getDefault().getISO3Country()
    }
}
